package servlet.Room;

import dao.UserDao;
import domain.User;
import service.room.RoomService;
import service.room.RoomServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class RoomStateYes extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public RoomStateYes() {
        super();
        // TODO Auto-generated constructor stub
    }


    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
        doPost(request, response);

    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        User user = (User)request.getSession().getAttribute("adminloginflag");
        if (user == null || request.getParameter("Room_id") == null ||user.getRoom_power()==0 ||user.getVerify_power()==0||user.getView_power()==null||user.getView_power().equals("null")) {
            request.getRequestDispatcher("/admin/error/error404.jsp").forward(request, response);
        } else {
            int Roomid = Integer.parseInt(request.getParameter("Room_id"));
            RoomService roomService = new RoomServiceImpl();
            int up = 0;
            up = roomService.StateYes(Roomid);
            if (up != 0)
                response.getWriter().write("1");
        }
    }
}
